package com.openvas.controller;

import java.util.List;
//    import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.openvas.commons.common.annotation.Log;
import com.openvas.commons.common.enums.BusinessType;
import com.openvas.domain.TableScanner;
import com.openvas.service.ITableScannerService;
import com.openvas.commons.common.core.controller.BaseController;
import com.openvas.commons.common.core.domain.AjaxResult;

import com.openvas.commons.common.core.page.TableDataInfo;

/**
 * 扫描仪Controller
 * 
 * @author ruoyi
 * @date 2021-11-04
 */
@Controller
@RequestMapping("/api/scanner")
public class TableScannerController extends BaseController
{
    private String prefix = "system/scanner";

    @Autowired
    private ITableScannerService tableScannerService;

   // //  @RequiresPermissions("system:scanner:view")
    @GetMapping()
    public String scanner()
    {
        return prefix + "/scanner";
    }

    /**
     * 查询扫描仪列表
     */
   // //  @RequiresPermissions("system:scanner:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TableScanner tableScanner)
    {
        startPage();
        List<TableScanner> list = tableScannerService.selectTableScannerList(tableScanner);
        return getDataTable(list);
    }

    /**
     * 导出扫描仪列表
     */
   // //  @RequiresPermissions("system:scanner:export")
    @Log(title = "扫描仪", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TableScanner tableScanner)
    {
        List<TableScanner> list = tableScannerService.selectTableScannerList(tableScanner);
//        ExcelUtil<TableScanner> util = new ExcelUtil<TableScanner>(TableScanner.class);
//        return util.exportExcel(list, "扫描仪数据");
        return null;
    }

    /**
     * 新增扫描仪
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存扫描仪
     */
   // //  @RequiresPermissions("system:scanner:add")
    @Log(title = "扫描仪", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TableScanner tableScanner)
    {
        return toAjax(tableScannerService.insertTableScanner(tableScanner));
    }

    /**
     * 修改扫描仪
     */
    @GetMapping("/edit/{scannerId}")
    public String edit(@PathVariable("scannerId") String scannerId, ModelMap mmap)
    {
        TableScanner tableScanner = tableScannerService.selectTableScannerByScannerId(scannerId);
        mmap.put("tableScanner", tableScanner);
        return prefix + "/edit";
    }

    /**
     * 修改保存扫描仪
     */
   // //  @RequiresPermissions("system:scanner:edit")
    @Log(title = "扫描仪", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TableScanner tableScanner)
    {
        return toAjax(tableScannerService.updateTableScanner(tableScanner));
    }

    /**
     * 删除扫描仪
     */
   // //  @RequiresPermissions("system:scanner:remove")
    @Log(title = "扫描仪", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tableScannerService.deleteTableScannerByScannerIds(ids));
    }
}
